
#include "arm_math.h"
#include "arm_const_structs.h"
#include <stdio.h>

#define TEST_LENGTH_SAMPLES 2048
#define FS 10000

extern float32_t testInput_f32_10khz[TEST_LENGTH_SAMPLES];
static float32_t testOutput[TEST_LENGTH_SAMPLES/2];


static uint32_t fftSize = 1024;
static uint32_t ifftFlag = 0;
static uint32_t doBitReverse = 1;
static arm_cfft_instance_f32 varInstCfftF32;

static int testIndex = 0;

static float testtmp_f32_10khz[2048];
static int32_t adcbuffer[2048];

int32_t frq_main(void)
{

  arm_status status;
  float32_t maxValue;

  status = ARM_MATH_SUCCESS;

  status=arm_cfft_init_f32(&varInstCfftF32,fftSize);

  //memcpy(testtmp_f32_10khz,testInput_f32_10khz,sizeof(testInput_f32_10khz));
  adc_samp(adcbuffer,2048);
  for(int i=0; i<2048;i ++)
 {
	  testtmp_f32_10khz[i] = (float)adcbuffer[i];
  }
  arm_cfft_f32(&varInstCfftF32, testtmp_f32_10khz, ifftFlag, doBitReverse);

  arm_cmplx_mag_f32(testtmp_f32_10khz, testOutput, fftSize);

  /* Calculates maxValue and returns corresponding BIN value */
  arm_max_f32(testOutput, fftSize, &maxValue, &testIndex);

  float freq = (FS/TEST_LENGTH_SAMPLES)*testIndex;
  float vpp = maxValue/(TEST_LENGTH_SAMPLES/2);
  float pha = atan2(testOutput[2*testIndex],testOutput[2*testIndex+1]);
  printf("freq=%f,vpp=%f,pha=%f\r\n",freq,vpp,pha);

}

 /** \endlink */
